//
//  BKFunctionModel.m
//  FastBee
//
//  Created by mac on 16/9/10.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKFunctionModel.h"
#import "BKNetWorkTools.h"


@implementation BKFunctionModel

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}

+ (instancetype)fuctionModelWithDic:(NSDictionary *)dic{

    BKFunctionModel *model = [[BKFunctionModel alloc]init];
    [model setValuesForKeysWithDictionary:dic];
    return model;
}

+ (void)downloadDataWithUrl:(NSString *)url successBlock:(void(^)(NSArray *arr))successBlock failBlock:(void(^)(NSError *error))failBlock{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:@"1" forKey:@"call"];

    [[BKNetWorkTools shareNetWorkTools]POST:url parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        
        //NSLog(@"%@",responseObject);
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSArray *arr = dic[@"icons"];
       
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:arr.count];
        for (NSDictionary *dic in arr) {
            
            BKFunctionModel *model = [BKFunctionModel fuctionModelWithDic:dic];
            [arrM addObject:model];
        }
        
        if (successBlock) {
            successBlock(arrM.copy);
        }

        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failBlock) {
            failBlock(error);
        }
    }];
}

@end
